<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>订单管理</title>
	<meta name="decorator" content="default"/>
	<link href="${ctxStatic}/jquery-select2/3.4/select2.min.css" rel="stylesheet" />
	<script src="https://select2.github.io/vendor/js/jquery.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
	<script src="${ctxStatic}/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$(".js-example-basic-single").select2();
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function excel(){
			$('#searchForm').attr('action',"${ctx}/jiujiu/jiuOrder/excel");
			$('#searchForm').submit();
		}
		function search(){
			$('#searchForm').attr('action',"${ctx}/jiujiu/jiuOrder");
			$('#searchForm').submit();
		}
		
		//结算
		function settle(id){
			var remarks=$('#remarks'+id).val();
			
			$.getJSON("${ctx}/jiujiu/jiuOrder/settle",{id:id,remarks:remarks}, function(data){
                alert(data.message); 
                if(data.msg=='success'){
                	var html='<a id="afan'+id+'" class="btn btn-success" href="#" data-toggle="modal" data-target="#stack1'+id+'">反审</a>';
                	$('#ajie'+id).after(html);
                	$('#ajie'+id).hide();
                	$('#sta'+id).html('已结算');
                }
            });
			
			$('#stack'+id).css('display','none');
			$('.modal-backdrop').remove();
		}
		
		//反审
		function sntiTrial(id){
			var remarks=$('#remark'+id).val();
			
			$.getJSON("${ctx}/jiujiu/jiuOrder/sntiTrial",{id:id,remarks:remarks}, function(data){
                alert(data.message); 
                if(data.msg=='success'){
                	var html='<a id="ajie'+id+'" class="btn btn-success" href="#" data-toggle="modal" data-target="#stack'+id+'">结算</a>';
                	$('#afan'+id).after(html);
                	$('#afan'+id).hide();
                	$('#sta'+id).html('已反审');
                }
            });
			
			$('#stack1'+id).css('display','none');
			$('.modal-backdrop').remove();
		}
	</script>
</head>
<body>
	<%-- <ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/jiujiu/jiuOrder/">订单列表</a></li>
		<shiro:hasPermission name="jiujiu:jiuOrder:edit"><li><a href="${ctx}/jiujiu/jiuOrder/form">订单添加</a></li></shiro:hasPermission>
	</ul> --%>
	<form:form id="searchForm" modelAttribute="jiuOrder" action="${ctx}/jiujiu/jiuOrder/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<label>订单号：</label><form:input path="startOrderNo" htmlEscape="false" maxlength="50" class="input-medium"/>  -至-
		<form:input path="endOrderNo" htmlEscape="false" maxlength="50" class="input-medium"/>
		<br />
		
		<label>门店名称 ：</label>
		<form:select path="storeId" class="js-example-basic-single">
			<form:option value="">全部</form:option>
			<c:forEach items="${JiuStoreList}" var="jiuStore">
                   <form:option value="${jiuStore.id}">${jiuStore.name}</form:option>
			</c:forEach>
       	</form:select>
		
		
		<label>厂家名称 ：</label>
		<form:select path="manufactorId" class="js-example-basic-single">
			<form:option value="">全部</form:option>
			<c:forEach items="${jiuManufactorList}" var="jiuManufactor">
                   <form:option value="${jiuManufactor.id}">${jiuManufactor.name}</form:option>
			</c:forEach>
       	</form:select>
       	
       	<label>状态 ：</label>
		<form:select path="states">
			<form:option value="">全部</form:option>
            <form:option value="0">商家未审核</form:option>
            <form:option value="1">商家已取消</form:option>
            <form:option value="2">下单成功</form:option>
            <form:option value="3">厂家申请撤销</form:option>
            <form:option value="4">厂家已撤销</form:option>
            <form:option value="5">完成</form:option>
            <form:option value="6">已结算</form:option>
             <form:option value="7">已反审</form:option>
            <form:option value="200">冻结中</form:option>
            <form:option value="300">未完结</form:option>
            <form:option value="400">已完结</form:option>
       	</form:select>
       	<br/>
       	<label>下单时间 ：</label>
				<input id="startTime" name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${jiuOrder.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/> -至-
						
				<input id="endTime" name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${jiuOrder.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/> 
		<br/><br/>					
		<label>完成时间 ：</label>
				<input id=startCompleteTime name="startCompleteTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${jiuOrder.startCompleteTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/> -至-
						
				<input id="endCompleteTime" name="endCompleteTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${jiuOrder.endCompleteTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/> 
		<br/><br/>				
		<label>结算时间 ：</label>
				<input id=startSettlemenTime name="startSettlemenTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${jiuOrder.startSettlemenTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/> -至-
						
				<input id="endSettlemenTime" name="endSettlemenTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${jiuOrder.endSettlemenTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
		
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="javascript:search()"/>
		&nbsp;<input class="btn btn-primary" type="button" value="导出" onclick="javascript:excel()"/>
	</form:form>
	<tags:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered ">
		<thead><tr>
		<th>订单号</th>
		<th>厂家名称</th>
		<th>门店名称</th>
		<th>传图设计师</th>
		<th>数量</th>
		<th>单价</th>
		<th>总价</th>
		<th>状态</th>
		<th>下单时间</th>
		<shiro:hasPermission name="jiujiu:jiuOrder:edit"><th>操作</th></shiro:hasPermission></tr></thead>
		<tbody>
		<c:forEach items="${page.list}" var="jiuOrder">
			<tr>
				<td>${jiuOrder.orderNo}</td>
				<td><a href="${ctx}/jiujiu/jiuManufactor?id=${jiuOrder.manufactorId}">${jiuOrder.manufactorName}</a></td>
				<td><a href="${ctx}/jiujiu/jiuStore?id=${jiuOrder.storeId}">${jiuOrder.storeName}</a></td>
				<td>${jiuOrder.designName}</td>
				<td>${jiuOrder.orderNum}</td>
				<td>${jiuOrder.unitPrice}</td>
				<td>${jiuOrder.totalPrice}</td>
				<td id="sta${jiuOrder.id}">
					<c:choose>
					    <c:when test="${jiuOrder.states eq 0}">
					        	商家未审核 
					    </c:when>
					    <c:when test="${jiuOrder.states eq 1}">
					        	商家已取消
					    </c:when>
					    <c:when test="${jiuOrder.states eq 2}">
					        	下单成功	
					    </c:when>
					    <c:when test="${jiuOrder.states eq 3}">
					        	厂家申请撤销
					    </c:when>
					    <c:when test="${jiuOrder.states eq 4}">
					        	厂家已撤销
					    </c:when>
					    <c:when test="${jiuOrder.states eq 5}">
					        	完成
					    </c:when>
					    <c:when test="${jiuOrder.states eq 6}">
					        	已结算
					    </c:when>
					     <c:when test="${jiuOrder.states eq 7}">
					        	已反审
					    </c:when>
					    <c:otherwise>
					    </c:otherwise>
					</c:choose>
				</td>
				<td><fmt:formatDate value="${jiuOrder.createTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" /></td>
				<shiro:hasPermission name="jiujiu:jiuOrder:edit"><td>
                 <c:if test="${jiuOrder.states eq 5}">
                 <!-- 结算 -->
                 <!-- 如果凭证不为空 -->
                 <c:if test="${not empty jiuOrder.uploadPic}">
                     <a id="ajie${jiuOrder.id}" class="btn btn-info" href="${ctx}/jiujiu/jiuOrder/viewOrderUploadPic?id=${jiuOrder.id}">查看凭证</a>	
                 </c:if>
                 </c:if>
				<a class="btn btn-success" href="#" data-toggle="modal" data-target="#myOrder_${jiuOrder.id}">详情</a>
				<c:set var="isJieSuan" value="${fn:indexOf(fns:getUser().roleIdList, '11') == -1}" scope="page"/>
				<c:set var="isFanShen" value="${fn:indexOf(fns:getUser().roleIdList, '12') == -1}" scope="page"/>
				
				<c:if test="${isJieSuan &&  isFanShen}">  <!-- 平台会计、平台出纳  无权结算、反审 -->
					<c:if test="${jiuOrder.states eq 5 || jiuOrder.states eq 7}">
						<a id="ajie${jiuOrder.id}" class="btn btn-warning" href="#" data-toggle="modal" data-target="#stack${jiuOrder.id}">结算</a>	
	                </c:if>
	                <c:if test="${jiuOrder.states eq 6}">
						<a id="afan${jiuOrder.id}" class="btn btn-warning" href="#" data-toggle="modal" data-target="#stack1${jiuOrder.id}">反审</a>	
	                </c:if>
                </c:if>
    				<%-- <a class="btn btn-success" href="${ctx}/jiujiu/jiuOrder/form?id=${jiuOrder.id}">修改</a>
					<a class="btn btn-danger" href="${ctx}/jiujiu/jiuOrder/delete?id=${jiuOrder.id}" onclick="return confirmx('确认要删除该订单吗？', this.href)">删除</a> --%>
				</td></shiro:hasPermission>
			</tr>
			
				<!--结算开始-->
				<div id="stack${jiuOrder.id}" class="modal hide fade" tabindex="-1" data-focus-on="input:first">
				  <div class="modal-header">
				    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				    <h3>请填写备注（选填）</h3>
				  </div>
				  <div class="modal-body">
							<label class="control-label">备注:</label>
							<div class="controls">
								<input id="remarks${jiuOrder.id}"  value=""/>
							</div>
				 		
				  </div>
				  <div class="modal-footer">
				    <button type="button" class="btn btn-primary" onclick="settle(${jiuOrder.id})">Ok</button>
				  </div>
				</div>
				<!--结算结束-->
				
				<!--反审开始-->
				<div id="stack1${jiuOrder.id}" class="modal hide fade" tabindex="-1" data-focus-on="input:first">
				  <div class="modal-header">
				    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				    <h3>请填写备注（选填）</h3>
				  </div>
				  <div class="modal-body">
							<label class="control-label">备注:</label>
							<div class="controls">
								<input id="remark${jiuOrder.id}"  value=""/>
							</div>
				 		
				  </div>
				  <div class="modal-footer">
				    <button type="button" class="btn btn-primary" onclick="sntiTrial(${jiuOrder.id})">Ok</button>
				  </div>
				</div>
				<!--反审结束-->
			
					<!-- 订单明细  开始-->
					<div id="myOrder_${jiuOrder.id}" class="modal hide fade" tabindex="-1" style="width:900px;margin-left:-500px;" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
								<h3 id="myModalLabel">明细</h3>
							</div>
											
							<div class="modal-body">
								<h6>门店</h6>
								
									<section class="gray-div">
										<div style="background: #FFFFFF; text-align: left; color: #666666;">
											<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">下单时间：<fmt:formatDate value="${jiuOrder.createTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---订单清单：${jiuOrder.detailedList}</br>操作者：${jiuOrder.designName}</p>
											<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">商家取消时间：<fmt:formatDate value="${jiuOrder.busCancelTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.busCancelRemarks}</br>操作者：${jiuOrder.cancelName}</p>
											<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">商家确认时间：<fmt:formatDate value="${jiuOrder.busConfirmTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.busConfirmRemarks}</br>操作者：${jiuOrder.confirmName}</p>
											<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">完成时间：<fmt:formatDate value="${jiuOrder.completeTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.completeRemarks}</br>操作者：${jiuOrder.takeName}</p>
										</div>
									</section>
									
									<h6>厂家</h6>
									<section class="gray-div">
										<div style="background: #FFFFFF; text-align: left; color: #666666;">
											<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">厂家申请撤销时间：<fmt:formatDate value="${jiuOrder.manApplyRevokeTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.manApplyRevokeRemarks}</br>操作者：${jiuOrder.applyName}</p>
											<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">厂家撤销时间：<fmt:formatDate value="${jiuOrder.manRevokeTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.manRevokeRemarks}</br>操作者：${jiuOrder.manRevokeName }</p>
										</div>
									</section>
									
									<h6>平台</h6>
									<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">结算时间：<fmt:formatDate value="${jiuOrder.settlementTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.settlementRemarks}</br>结算人：${jiuOrder.settlementRen}</p>
									<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">反审时间：<fmt:formatDate value="${jiuOrder.trialTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.trialRemarks}</br>反审人：${jiuOrder.trialRen}</p>
									
									<h6>申请反审</h6>
									<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">申请反审时间：<fmt:formatDate value="${jiuOrder.applyFanshenTime}" type="both" pattern="yyyy-MM-dd HH:mm:ss" />---备注：${jiuOrder.applyFanshenRemarks}</br></p>
									<p style="font-size: 14px; padding: 10px 10px 2.5px 10px;">申请反审人：${jiuOrder.applyFanshenName}</p>
									
							</div>
							<div class="modal-footer">
								<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
							</div>
					</div> 
					<!-- 订单明细  结束-->				
					
		</c:forEach>
		<tr>
		<td>--</td><td>--</td><td>--</td><td>--</td>
		<td>${sum[0]}</td><td>${sum[1]}</td><td>${sum[2]}</td><td>--</td>
		<td>--</td><td>--</td>
		</tr>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>
